package org.ihelpuoo.weboo.tag.core;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import org.ihelpuoo.weboo.exception.ModuleNotFoundException;
import org.ihelpuoo.weboo.module.Module;
import org.ihelpuoo.weboo.tag.WebooTag;

public class UrlTag extends WebooTag
{

	private static final long	serialVersionUID	= 2545160869681670077L;

	private String				src;
	private String				module;

	public String getSrc()
	{
		return src;
	}

	public void setSrc(String value)
	{
		this.src = value;
	}

	public String getModule()
	{
		return module;
	}

	public void setModule(String module)
	{
		this.module = module;
	}

	@Override
	public void end() throws JspException
	{
		try
		{
			try
			{
				Module m = getModule(module);
				pageContext.getOut().write(getContextPath() + "/" + m.getName() + "/" + src);
			}
			catch (ModuleNotFoundException e)
			{
				pageContext.getOut().write(getContextPath() + "/" + src);
			}
		}
		catch (IOException e)
		{
			throw new JspException(e);
		}
	}

	@Override
	protected void start() throws JspException
	{
	}

}
